home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / imb9011.zip / FILELOCK.BAS < prev    next >
BASIC Source File  |  1990-11-01  |  2KB  |  87 lines

  1. '*** Program FILELOCK.BAS ***************************************
  2.  
  3. TYPE InvoiceHdr
  4.     InvoiceNbr AS LONG
  5.     AcctNbr AS STRING * 6
  6.     Terms AS STRING * 20
  7.     InvoiceTotal AS CURRENCY
  8. END TYPE
  9.  
  10. DECLARE SUB ChangeRecord (e AS InvoiceHdr)
  11. DECLARE SUB GetData (e AS InvoiceHdr)
  12. DECLARE SUB AddRecord (e AS InvoiceHdr)
  13.  
  14. DIM InvoiceHdrRec AS InvoiceHdr
  15. DIM LastRecord, RecNo AS LONG
  16. ON ERROR GOTO ErrorHandler
  17. OPEN "INVHDR.DAT" FOR RANDOM SHARED AS #1 LEN = LEN(InvoiceHdrRec)
  18.  
  19. DO
  20.  CLS
  21.  PRINT "(A)dd a record, (C)hange a record, or (Q)uit ";
  22.  Choice$ = INPUT$(1)
  23.  Choice$ = UCASE$(Choice$)
  24.  PRINT Choice$
  25.  LastRecord = LOF(1) / LEN(InvoiceHdrRec)
  26.  SELECT CASE Choice$
  27.      CASE "A"
  28.         CALL AddRecord(InvoiceHdrRec)
  29.         PUT 1, LastRecord + 1, InvoiceHdrRec
  30.      CASE "C"
  31.         PRINT "Enter the number of the record to update (1 to";
  32.         PRINT LastRecord; ")"
  33.         DO
  34.          INPUT "Record Number "; RecNo
  35.         LOOP UNTIL RecNo > 0 AND RecNo <= LastRecord
  36. TryLock:
  37.         LOCK 1, RecNo
  38.         GET 1, RecNo, InvoiceHdrRec
  39.         CALL ChangeRecord(InvoiceHdrRec)
  40.         PUT 1, RecNo, InvoiceHdrRec
  41.         UNLOCK 1, RecNo
  42.      CASE "Q"
  43.  END SELECT
  44. EndLoop:
  45. LOOP UNTIL Choice$ = "Q"
  46.  
  47. CLOSE #1
  48.  
  49. ErrorHandler:
  50. SELECT CASE ERR
  51.  CASE 70
  52.     LOCATE 22, 10: PRINT "Record"; RecNo; "is currently in use"
  53.     LOCATE 23, 10: PRINT "Would you like to try again (Y/N)"
  54.     Try$ = INPUT$(1)
  55.     Try$ = UCASE$(Try$)
  56.     LOCATE 22, 10: PRINT SPACE$(60)
  57.     LOCATE 22, 10: PRINT SPACE$(60)
  58.     IF Try$ = "Y" THEN CLS : RESUME TryLock ELSE RESUME EndLoop
  59. END SELECT
  60.  
  61. SUB AddRecord (NewRecord AS InvoiceHdr)
  62.     CALL GetData(NewRecord)
  63. END SUB
  64.  
  65. SUB ChangeRecord (ChgRecord AS InvoiceHdr)
  66.  PRINT "Old Record"
  67.  PRINT USING "Invoice Number: ##########            ";_
  68.                                  ChgRecord.InvoiceNbr
  69.  PRINT USING "Account Number: \                    \";_
  70.                                  ChgRecord.AcctNbr
  71.  PRINT USING "Terms:          \                    \";_
  72.                                  ChgRecord.Terms
  73.  PRINT USING "Invoice Total   $$,#####.##           ";_
  74.                                  ChgRecord.InvoiceTotal
  75.  PRINT
  76.  PRINT "Enter New Data:"
  77.  CALL GetData(ChgRecord)
  78. END SUB
  79.  
  80. SUB GetData (e AS InvoiceHdr)
  81.     INPUT "Invoice Number "; e.InvoiceNbr
  82.     INPUT "Account Number "; e.AcctNbr
  83.     INPUT "Terms          "; e.Terms
  84.     INPUT "Invoice Total  "; e.InvoiceTotal
  85. END SUB
  86.  
  87.